﻿using System;
using System.Runtime.Serialization;
using System.Text;

namespace PhiStore.Experiments.Serialize
{
    [Serializable()]
    class ConstructorSerializable : ISerializable
    {
        private int _number1;
        private decimal _number2;
        private string _text;
        private byte _data1;
        private byte[] _data2;

        public ConstructorSerializable(string input)
        {
            _text = input;
            _data2 = ASCIIEncoding.ASCII.GetBytes(input);
            _data1 = _data2[0];
            _number1 = (int)_data1;
            _number2 = new decimal(_number1);
        }

        public ConstructorSerializable(SerializationInfo info, StreamingContext context)
        {
            this._data1 = info.GetByte("d");
            this._data2 = (byte[])info.GetValue("e", typeof(byte[]));
            this._number2 = info.GetDecimal("b");
            this._number1 = info.GetInt32("a");
            this._text = info.GetString("c");
        }

        public int number1{ get{ return _number1;} }
        public decimal number2 { get { return _number2; } }
        public string text { get { return _text; } }
        public byte data1 { get { return _data1; } }
        public byte[] data2 { get { return _data2; } }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("a", this._number1);
            info.AddValue("b", this._number2);
            info.AddValue("c", this._text);
            info.AddValue("d", _data1);
            info.AddValue("e", _data2);
        }
    }
}
